package cyb.test;

import cn.hutool.json.JSONUtil;
import cyb.CoLocation;
import cyb.POI;
import cyb.Properties;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;

class point {
    String gender;
    double xx;
    double yy;
    String id;

    public point() {
    }

    public point(String gender, double xx, double yy, String id) {
        this.gender = gender;
        this.xx = xx;
        this.yy = yy;
        this.id = id;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public double getXx() {
        return xx;
    }

    public void setXx(double xx) {
        this.xx = xx;
    }

    public double getYy() {
        return yy;
    }

    public void setYy(double yy) {
        this.yy = yy;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "{" +
                "gender:'" + gender + '\'' +
                ", xx:" + xx +
                ", yy:" + yy +
                ", id:" + id +
                '}';
    }
}

public class savejson {
    public static void main(String[] args) {
        double maxX = 10000d;
        double minX = (double) 0;
        double maxY = 10000d;
        double minY = (double) 0;
        Random rd = new Random();

        String path = "C:\\Users\\chenyb\\Desktop\\pointSet.json";
        try (BufferedWriter bw = new BufferedWriter(new FileWriter(path))) {
            List<point> list = new LinkedList<>();
            Map<Integer,Integer> typeNumMap = new HashMap<>();
//            for (int i = 0; i < 1000; i++) {
//                String id = String.valueOf(i);
//                double X = Math.abs(rd.nextDouble()) * 10000;
//                double Y = Math.abs(rd.nextDouble()) * 10000;
//                int type = Math.abs(rd.nextInt()) % 10;
//
//                if (X > maxX) maxX = X;
//                if (X < minX) minX = X;
//                if (Y > maxY) maxY = Y;
//                if (Y < minY) minY = Y;
//                point node = new point(String.valueOf(type), X, Y, id);
//                list.add(node);
//            }
            for (int i = 0; i < 100; i++) {
                String id = String.valueOf(i);
                double X = Math.abs(rd.nextDouble()) * 10000;
                double Y = Math.abs(rd.nextDouble()) * 10000;
                int type = Math.abs(rd.nextInt()) % 10;

                if (X > maxX) maxX = X;
                if (X < minX) minX = X;
                if (Y > maxY) maxY = Y;
                if (Y < minY) minY = Y;
                point node = new point(String.valueOf(type), X, Y, id);
                list.add(node);
                Integer integer = typeNumMap.computeIfAbsent(type, k -> 0);
                typeNumMap.put(type,integer+1);
            }
            String s2 = JSONUtil.toJsonStr(list);

            bw.write(s2);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
